
import 'package:flutter/material.dart';

class JKSubjectDetailPage extends StatelessWidget {
  static const String routeName = "/subjectdetail";

  @override
  Widget build(BuildContext context) {
    final String message = ModalRoute.of(context).settings.arguments as String;

    return WillPopScope(
      onWillPop: () {
        Navigator.of(context).pop("a back detail message");
        return Future.value(false);
      },
      child: Scaffold(
        appBar: AppBar(
          title: Text('书影集详情'),
        ),
        body: JKSubjectDetailContent(),
      ),
    );
  }
}

class JKSubjectDetailContent extends StatefulWidget {
  @override
  _JKSubjectDetailContentState createState() => _JKSubjectDetailContentState();
}

class _JKSubjectDetailContentState extends State<JKSubjectDetailContent> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text(''),
          RaisedButton(
            child: Text('返回上个界面'),
            onPressed: () {
              print('返回上个界面');
              _popLastPage(context);
            },
          ),
        ],
      ),
    );
  }

  void _popLastPage(BuildContext context) {
    // pop<T extends Object>([ T result ]) 返回的结果是一个泛型
    Navigator.of(context).pop('我是返回的结果');
  }
}
